package com.bm.greeting;

import com.bm.greeting.config.BaseInfoConfig;
import com.bm.greeting.config.Pusher;
import com.bm.greeting.config.SendWxMessageUtil;
import com.bm.greeting.service.impl.SendMail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import static com.bm.greeting.config.SendWxMessageUtil.sendTextMsg;

/**
 * @author Jinmy
 */
@SpringBootApplication
@EnableScheduling
public class GreetingApplication {

    @Autowired
    private SendMail sendMail;

    public static void main(String[] args) {
        SendWxMessageUtil.sendTextMsgData("YiZhi", SendWxMessageUtil.test(), sendTextMsg());
        Pusher.returnBm(BaseInfoConfig.EVERY_DAY_WECHAT_PUSH, BaseInfoConfig.SUCCESS);
        SpringApplication.run(GreetingApplication.class, args);
    }


    @Scheduled(cron = "0 0 8 * * ?")
    public void goodMorning() {
        try {
            Pusher.pushBaby();
            Pusher.returnBm(BaseInfoConfig.EVERY_DAY_GOOD_MORNING_PUSH, BaseInfoConfig.SUCCESS);
        } catch (Exception e) {
            Pusher.returnBm(BaseInfoConfig.EVERY_DAY_GOOD_MORNING_PUSH, BaseInfoConfig.FAIL);
        }
    }

    @Scheduled(cron = "0 0 8 * * ?")
    public void goodMorningSms() {
        try {
            Pusher.returnBm(BaseInfoConfig.EVERY_DAY_SMS_PUSH, BaseInfoConfig.SUCCESS);
        } catch (Exception e) {
            Pusher.returnBm(BaseInfoConfig.EVERY_DAY_SMS_PUSH, BaseInfoConfig.FAIL);
        }
    }

    @Scheduled(cron = "0 0 8 * * ?")
    public void send() {
        try {
            SendWxMessageUtil.sendTextMsgData(BaseInfoConfig.ALL, SendWxMessageUtil.test(), sendTextMsg());
            Pusher.returnBm(BaseInfoConfig.EVERY_DAY_WECHAT_PUSH, BaseInfoConfig.SUCCESS);
        } catch (Exception e) {
            Pusher.returnBm(BaseInfoConfig.EVERY_DAY_WECHAT_PUSH, BaseInfoConfig.FAIL);
        }
    }

}
